package mao.thinkinjava.concurency.countdownlatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownLatchDemo {
    private static int size = 100;
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        CountDownLatch latch = new CountDownLatch(size);
        for (int i = 0; i < 10; i++) {
            WaitThread waitThread = new WaitThread(latch);
            exec.submit(waitThread);
        }
        for (int i = 0; i < size; i++) {
            exec.submit(new PortionTask(latch));
        }
        exec.shutdown();
    }
}
